package com.jf3q.iot.exception;

import com.jf3q.iot.dto.ResultBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    //指定出现什么异常执行这个方法
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody //为了返回数据
    public ResultBean error(RuntimeException e) {
        e.printStackTrace();
        return ResultBean.error(e.getMessage());
    }
}
